/*  $ID: utils.js */

var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);

var Utils = new Object();

Utils.htmlEncode = function(text)
{
	return text.replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

Utils.trim = function(text)
{
	if(typeof(text) == "string")
	{
		return text.replace(/^\s*|\s*$/g,"");
	}
	else
	{
		return text;
	}
}

Utils.isEmpty = function(val)
{
	switch(typeof(val))
	{
		case 'string':
			return Utils.trim(val).length == 0 ? true : false;
			break;
		case 'number':
			return val == 0;
			break;
		case 'object':
			return val == null;
			break;
		case 'array':
			return val.length == 0;
			break;
		default:
			return true;
	}
}

Utils.isNumber = function(val)
{
	var reg = /^[\d|\.|,]+$/;
	return reg.test(val);
}

Utils.isInt = function(val)
{
	if(val == "")
	{
		return false;
	}
	var reg = /\D+/;
	return !reg.test(val);
}

Utils.isEmail = function(email)
{
	var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
	return reg1.test(email);
}

Utils.isTel = function (tel)
{
	var reg = /^[\d|\-|\s|\_]+$/;
	return reg.test(tel);
}

Utils.fixEvent = function(e)
{
	var evt = (typeof e == "undefined") ? window.event : e;
	return evt;
}

Utils.srcElement = function(e)
{
	
}

Utils.isTime = function(val)
{
	
}

Utils.$ = function(name)
{
	return document.getElementById(name);
}

document.getCookie = function(sName)
{
	var aCookie = document.cookie.split("; ");
	for(var i=0;i<aCookie.length;i++)
	{
		var aCrumb = aCookie[i].split("=");
		if(sName == aCrumb[0])
		{
			return decodeURIComponent(aCrumb[1]);
		}
	}
	return null;
}

document.setCookie = function(sName,sValue,sExpires)
{
	var sCookie = sName + "=" +encodeURIComponent(sValue);
	if(sExpires != null)
	{
		sCookie += "; expires="+ sExpires;
	}
	
	document.cookie = sCookie;
}

document.removeCookie = function(sName,sValue)
{
	document.cookie= sName + "=; expires = Fri,31 Dec 1999 23:23:23;";
}



